package com.indictor.bean;

import java.math.BigDecimal;

public class DefaultIndicatorCalculator extends CalculatorBase implements IndicatorCalculator {

    private BigDecimal value1;
    private String type = "-1";


    @Override
    public void calculate(Indicator indicator, BigDecimal value2) {
        if (type.equals("-1")) {
            value1 = value2;

        } else {
            value1 = super.calculate(value1, value2, this.type);
        }
        this.type = indicator.getType();
    }

    public BigDecimal getValue() {
        return value1;
    }


    @Override
    public void calculate(Indicator indicator, Object value) {

    }

    @Override
    public void calculate(Indicator indicator, Indicator left, Indicator right) {

        if (left == null && right == null) {
            System.out.println(indicator.getKey() + " " + indicator.getValue());
            indicator.setValue(indicator.getValue());
            return;
        }
        indicator.setValue(super.calculate(left == null ? null : left.getValue(), right == null ? null : right.getValue(), indicator.getType()));
        this.value1 = indicator.getValue();
    }
}
